﻿<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title></title>
<link rel="stylesheet" href="lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
</head>
<body class="pos-r">
<div class="pos-a" style="width:200px;left:0;top:0; bottom:0; height:100%; border-right:1px solid #e5e5e5; background-color:#f5f5f5; overflow:auto;">
	<ul id="treeDemo" class="ztree"></ul>
</div>
<div style="margin-left:200px;">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe64b;</i> 机构管理 <span id="officeNameSpan"> </span> <span class="c-gray en">&gt;</span> 用户列表 </nav>
	<div class="page-container">
		<!-- <div class="text-c"> 日期范围：
			<input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" id="datemin" class="input-text Wdate" style="width:120px;">
			-
			<input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:120px;">
			<input type="text" class="input-text" style="width:250px" placeholder="输入会员名称、电话、邮箱" id="" name="">
			<button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
		</div> -->
		<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l">
			<a href="javascript:;" onclick="batchdel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
			<a href="javascript:;" onclick="user_add('添加用户','office-user-add.html','','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加用户</a></span> 
			<span class="r">共有数据：<strong id="count"></strong> 条</span> </div>
		<div class="mt-20">
		<input type="hidden" id="officeId" name="officeId" value="">
		<input type="hidden" id="officeName" name="officeName" value="">
		<table class="table table-border table-bordered table-hover table-bg table-sort">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="80">登录名</th>
					<th width="80">用户名</th>
					<th width="80">工号</th>
					<th width="">角色</th>
					<th width="100">联系方式</th>
					<th width="140">最后登录时间</th>
					<th width="30">状态</th>
					<th width="90">操作</th>
				</tr>
			</thead>
			<tbody id="data">
				
			</tbody>
		</table>
		</div>
	</div>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->
<script type="text/javascript" src="static/h-ui.admin/js/common.js"></script>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
var setting = {
	view: {
		dblClickExpand: false,
		showLine: false,
		selectedMulti: false
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pId",
			rootPId: ""
		}
	},
	callback: {
		beforeClick: function(treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("tree");
			//alert("id:"+treeNode.id);
			//alert("treeId:"+treeId);
			loadUserData(treeNode.id);
			
			$("#officeId").val(treeNode.id);
			$("#officeName").val(treeNode.name);
			$("#officeNameSpan").html('<span class="c-gray en">&gt;</span> '+treeNode.name);
		}
	}
};
function sortDataTable(){
	$('.table-sort').dataTable({
		"aaSorting": [[ 1, "desc" ]],//默认第几个排序
		"bStateSave": true,//状态保存
		"destroy":true,
		"aoColumnDefs": [
		  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
		  {"orderable":false,"aTargets":[0,7,8]}// 制定列不参与排序
		]
	});
}
function cleanDataTable(){
	if ($('.table-sort').hasClass('dataTable')) {
		var dttable = $('.table-sort').dataTable();
		dttable.fnClearTable(); //清空一下table
		dttable.fnDestroy(); //还原初始化了的datatable
	}
}

$(function(){
	loadData();
});
//加载数据
function loadData(){
	var url = "/office/list";
	common.getData(url,function(data){
		//var params = common.getParams();
		var list = data.result;
		var html="";
		var zNodes = [];
		for(var i=0;i<list.length;i++){
			var obj = list[i];
			var n = {id:obj.id,pId:obj.parentId,name:obj.name};
			//if(params.officeId){
				//n["open"]="true";
				//$("#officeId").val(params.officeId);
				//$("#officeName").val(params.officeName);
				//$("#officeNameSpan").html('<span class="c-gray en">&gt;</span> '+params.officeName);
			//}
			zNodes.push(n);
		}
		initTree(zNodes);
		//loadUserData(params.officeId);
	});
}
function officeReloadUserData(){
	var params = common.getParams();
	loadUserData(params.officeId);
}
//初始加载左侧菜单
function initTree(zNodes){
	var t = $("#treeDemo");
	t = $.fn.zTree.init(t, setting, zNodes);
}
//加载页面数据
function loadUserData(officeId){
	if(!officeId){
		return;
	}
	var url = "/officeUser/getUsersByOfficeId?officeId="+officeId;
	common.getData(url,function(data){
		cleanDataTable();
		var list = data.result;
		var html="";
		for(var i=0;i<list.length;i++){
			var obj = list[i];
			html+='<tr class="text-c">\
				<td><input type="checkbox" value="'+obj.user.id+'" name="id"></td>\
				<td>'+obj.user.loginName+'</td>\
				<td>'+obj.user.name+'</td>\
				<td>'+obj.user.code+'</td>\
				<td>'+obj.user.extraData.roleStr+'</td>\
				<td>'+obj.user.contactWay+'</td>\
				<td>'+common.formatDate(obj.user.lastLoginTime)+'</td>\
				<td class="td-status">'+getStatusHtml(obj.user.status)+'</td>\
				<td class="td-manage">'+getEditStatusHtml(obj.user)+'\
				<a title="编辑" href="javascript:;" onclick="user_edit(\'编辑\',\'office-user-add.html\',\'\',\'510\',\''+obj.user.id+'\',\''+obj.user.name+'\',\''+obj.user.code+'\',\''+obj.user.contactWay+'\')" class="ml-5" style="text-decoration:none">\
				<i class="Hui-iconfont">&#xe6df;</i></a> <a style="text-decoration:none" class="ml-5" onClick="reset_password(\''+obj.user.loginName+'\')" href="javascript:;" title="重置密码"><i class="Hui-iconfont">&#xe63f;</i></a> <a title="删除" href="javascript:;" onclick="user_del(\''+obj.user.id+'\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>\
			</tr>';
		}
		$("#data").html(html);
		$("#count").html(list.length);
		if(list.length>0){
			sortDataTable();
		}
	});
}
//判断获取用户状态
function getStatusHtml(status){
	if(status==0){
		return '<span class="label label-success radius">已启用</span>';
	}else if(status==1){
		return '<span class="label label-error radius">已停用</span>';
	}else{
		return '<span class="label label-error radius red">账号异常</span>';
	}
}
function getEditStatusHtml(obj){
	if(obj.status==0){
		return '<a style="text-decoration:none" onClick="user_edit_status(this,\''+obj.id+'\',\'停用\',\'1\')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe706;</i></a>';
	}else if(obj.status==1){
		return '<a style="text-decoration:none" onClick="user_edit_status(this,\''+obj.id+'\',\'启用\',\'0\')" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe615;</i></a>';
	}else{
		return '';
	}
}
/*用户-添加*/
function user_add(title,url,w,h){
	var officeId = $("#officeId").val();
	if(!officeId){
		common.alertX("请选择所属机构.");
		return;
	}
	common.addParams({func:"add",officeId:$("#officeId").val(),officeName:$("#officeName").val()});
	layer_show(title,url,w,h);
}
function user_edit(title,url,w,h,id,name,code,contactWay){
	common.addParams({id:id,name:name,code:code,contactWay:contactWay,func:"edit",officeId:$("#officeId").val(),officeName:$("#officeName").val()});
	layer_show(title,url,w,h);
}
/*用户状态编辑*/
function user_edit_status(obj,id,msg,status){
	layer.confirm('确认要'+msg+'吗？',function(index){
		var data={id:id,status:status};
		var url = "/user/editStatus";
		common.postData(url,data,function(data){
			layer.msg(data.msg,{icon:1,time:1000});
			loadUserData($("#officeId").val());
		});
	});
}
/*重置密码*/
function reset_password(loginName){
	layer.confirm('确认要重置密码吗？',function(index){
		var data={loginName:loginName};
		var url = "/user/resetPassword";
		common.postData(url,data,function(data){
			layer.msg(data.msg,{icon:1,time:1000});
		});
	});
}

/*删除用户*/
function user_del(id){
	layer.confirm('确认要删除吗？',function(index){
		var data={id:id};
		var url = "/user/delUser";
		common.postData(url,data,function(data){
			layer.msg(data.msg,{icon:1,time:1000});
			loadUserData($("#officeId").val());
		});
	});
}
/*批量删除*/
function batchdel(){
	var ids = [];
	$('input[name="id"]:checked').each(function(i,e){ 
		<!-- ids[i]=$(e).val(); -->
		ids.push($(e).val());
	}); 
	
	if(ids.length>0){
		layer.confirm('确认要批量删除吗？',function(index){
			var data={ids:ids};
			debugger;
			var url = "/user/batchDel";
			common.postData(url,data,function(data){
				layer.msg(data.msg,{icon:1,time:1000});
				loadUserData($("#officeId").val());
			});
			
		});
	}else{
		common.alertX("请选择要删除的数据.");
	}
}
</script>
</body>
</html>